package com.transaction.utils;

import cn.hutool.jwt.JWT;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: TODO
 * @Author 卟哭！
 * @Date 2024/03/26  18:40
 * @Version 1.0
 */
public  class JwtUtils {
    /**
     * 通过token获取当前登录用户id
     * @param request
     * @return
     */
    public static Long GetUserIdByToken(HttpServletRequest request){
    String token = request.getHeader("token");
    if (token != null) {
        final JWT jwt = cn.hutool.jwt.JWTUtil.parseToken(token);
        String userId = jwt.getPayload("user_id").toString();

        return Long.valueOf(userId);
    }
        return null;
}

}
